package com.jing.weibo.service.user;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.jing.weibo.mapper.user.UserMpMapper;
import com.jing.weibo.pojo.user.UserInfo;
import com.jing.weibo.pojo.user.UserMp;

/**
 * 可互粉的用户的Service
 * @author jing.yue
 * @version 2012/11/13 1.0.0
 */
@Component
public class UserMpService {

	@Autowired
	private UserMpMapper userMpMapper;

	/**
	 * 保存可互粉用户信息
	 * @param userInfo
	 * @throws Exception
	 */
	public void saveUserMp(UserInfo userInfo) throws Exception {
		UserMp userMp = new UserMp();
		userMp.setUsername(userInfo.getUsername());
		userMp.setNickname(userInfo.getNickname());
		userMp.setToken(userInfo.getToken());
		userMp.setAttentionnum(userInfo.getAttentionnum());
		userMp.setFansnum(userInfo.getFansnum());
		userMp.setGender(userInfo.getGender());
		userMp.setWeibonum(userInfo.getWeibonum());
		userMp.setImg(userInfo.getImg());
		userMp.setVerified(userInfo.getVerified());
		userMpMapper.saveUserMp(userMp);
	}

	/**
	 * 根据用户名查询对象
	 * @param username
	 * @return
	 * @throws Exception
	 */
	public UserMp findByUsername(String username) throws Exception {
		return userMpMapper.findByUsername(username);
	}

	/**
	 * 根据用户名修改信息
	 * @param userInfo
	 * @throws Exception
	 */
	public void updateUserMp(UserInfo userInfo) throws Exception {
		UserMp userMp = new UserMp();
		userMp.setUsername(userInfo.getUsername());
		userMp.setNickname(userInfo.getNickname());
		userMp.setToken(userInfo.getToken());
		userMp.setAttentionnum(userInfo.getAttentionnum());
		userMp.setFansnum(userInfo.getFansnum());
		userMp.setGender(userInfo.getGender());
		userMp.setWeibonum(userInfo.getWeibonum());
		userMp.setImg(userInfo.getImg());
		userMp.setVerified(userInfo.getVerified());
		userMpMapper.updateUserMp(userMp);
	}

	/**
	 * 根据用户名删除可互粉用户信息
	 * @param username
	 * @throws Exception
	 */
	public void deleteByUsername(String username) throws Exception {
		userMpMapper.deleteByUsername(username);
	}

	/**
	 * 根据泡吧分区获取下面的所有用户信息
	 * @param userInfo
	 * @return
	 * @throws Exception
	 */
	public List<UserMp> findByJoinMpPbTypeUserMp(UserInfo userInfo) throws Exception {
		//userInfo.setStringtime(DateUtil.getTodayYyyyMmDdMaxHhmmss());
		return userMpMapper.findByJoinMpPbTypeUserMp(userInfo);
	}

	/**
	 * 查看没有分区的用户
	 * @param userInfo
	 * @param freezeUsers
	 * @return
	 * @throws Exception
	 */
	public List<UserMp> findByNotPbTypeUserMp(UserInfo userInfo, List<String> freezeUsers) throws Exception {
		//userInfo.setStringtime(DateUtil.getTodayYyyyMmDdMaxHhmmss());
		if(freezeUsers != null && freezeUsers.size() > 0) {
			userInfo.setUsernames(freezeUsers.toArray(new String[freezeUsers.size()]));
		}
		return userMpMapper.findByNotPbTypeUserMp(userInfo);
	}
}